from base.basepage import BasePage
from common.Tools import Tools


class General(BasePage, metaclass=Tools):
    OK = 'ok.jpg'
    CLOSE = 'close.jpg'
    CANCEL = 'cancel.jpg'
    MAX_BUTTON = 'max_button.jpg'
    LEVEl_UP = 'level_up.jpg'
    ADD = 'add.jpg'
    MAGULO = 'magulo.jpg'
    HAMBURGER = 'hamburger.jpg'
    FOOD_USE_LIMIT = 'food_use_limit.jpg'
    CHALLENGE = 'challenge.jpg'
    COMBAT_START = 'combat_start.jpg'
    UNSELECTED = 'unselected.jpg'
    SELECTED = 'selected.jpg'
    NEXT = 'next.jpg'
    RECEIVE = 'receive.jpg'
    ALL_RECEIVE = 'all_receive.jpg'
    WIN = 'win.jpg'
    TASK = 'task.jpg'

    def click_close(self):
        return self.click_match_xy(self.CLOSE)

    def click_ok(self):
        return self.click_match_xy(self.OK)

    def click_max_button(self):
        return self.click_match_xy(self.MAX_BUTTON)

    def click_cancel(self):
        return self.click_match_xy(self.CANCEL)

    def level_up_confirm(self):
        return self.click_match_xy(self.LEVEl_UP)

    def add(self):
        return self.click_match_xy(self.ADD)

    def click_magulo(self):
        return self.click_match_xy(self.MAGULO)

    def click_hamburger(self):
        return self.click_match_xy(self.HAMBURGER)

    def click_challenge(self, template_index):
        return self.click_match_xy(self.CHALLENGE, template_index)

    def click_combat_start(self):
        return self.click_match_xy(self.COMBAT_START)

    def click_unselected(self):
        return self.click_match_xy(self.UNSELECTED)

    def click_next(self):
        return self.click_match_xy(self.NEXT,threshold=0.75)

    def click_receive(self):
        return self.click_match_xy(self.RECEIVE)

    def click_all_receive(self):
        return self.click_match_xy(self.ALL_RECEIVE)

    def click_task(self):
        return self.click_match_xy(self.TASK)


    def add_energy(self):
        self.click_max_button()
        self.click_ok()
        self.click_ok()
        self.click_close()

    def food_eat(self):
        print('补充体力中')
        if self.get_match_xy(self.FOOD_USE_LIMIT):
            # 食用鲔当劳
            self.click_magulo()
            if self.get_match_xy(self.FOOD_USE_LIMIT):
                # 食用起司汉堡
                self.click_hamburger()
            self.add_energy()
        else:
            # 食用鲔鱼三明治
            self.add_energy()
